package com.tecsup.com.util;

import java.util.Collection;
import com.tecsup.excepcion.DAOExcepcion;

import com.tecsup.com.modelo.Pronosticos;
import com.tecsup.com.dao.PronosticosDAO;

public class PronosticosNegocio {

	public void insertarPronostico(String a, String b, int c, double d) throws DAOExcepcion {
		Pronosticos vo = new Pronosticos();
		vo.setProducto(a);
		vo.setPeriodo(b);
		vo.setDemanda(c);
		vo.setPronostico(d);

		PronosticosDAO dao = new PronosticosDAO();
		try {
			dao.insertar(vo);
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
		}
	}

	public void actualizarPronosticos(String a, String b, int c, double d,
			int id) throws DAOExcepcion {
		Pronosticos vo = new Pronosticos();
		vo.setProducto(a);
		vo.setPeriodo(b);
		vo.setDemanda(c);
		vo.setPronostico(d);
		vo.setIdPronostico(id);

		PronosticosDAO dao = new PronosticosDAO();
		try {
			dao.actualizar(vo);
		} catch (DAOExcepcion e) {
			System.out.println(e.getMessage());
		}
	}

	public Collection<Pronosticos> buscarPorProductoPronosticos(String producto) throws DAOExcepcion {
		PronosticosDAO dao = new PronosticosDAO();
		return dao.buscarPorProducto(producto);
	}
	
	public Collection<Pronosticos> listarPronosticos() throws DAOExcepcion {
		PronosticosDAO dao = new PronosticosDAO();
		return dao.listar();
	}

	public Pronosticos obtenerPronosticos(int idPronostico) throws DAOExcepcion {
		PronosticosDAO dao = new PronosticosDAO();
		return dao.obtener(idPronostico);
	}
	
	public String[] graficoBarras(String producto) throws DAOExcepcion {
		
		PronosticosDAO dao = new PronosticosDAO();
		Collection<Pronosticos> pr  = dao.buscarPorProducto(producto);
		
		String[] columnas = new String[pr.size()];
		int c = 0;
		for (Pronosticos p:pr) {
			columnas[c] = p.getProducto();
			c++;
		}
				
		String[] filax = new String[pr.size()];
		int i = 0;
		for (Pronosticos p:pr){
			filax[i] = p.getPeriodo();
			c++;
		}
		return columnas;
}
}